<?php
	class Subscribe_Model extends CI_Model {
		function __construct()
		{
			parent::__construct();	
		}
		
		function lists($p=1,$limit=50)
		{
			$start = ($p-1)*50;
			$this->db->order_by("name", "asc");
			$this->db->limit($limit , $start);
			$this->db->from('subscriber');
			$query = $this->db->get();
			return $query->result();
		}
		
		function add($input)
		{
			if($input['name'] != null) {
				$data = array(
					'name' => $input['name'] ,
					'email' => $input['email']
				); 
				$this->db->insert('subscriber', $data);
				return $this->db->insert_id();
			}else{
				return 0;
			}
		}
		
		function status($id)
		{
			if($this->session->userdata('admin_logged_in') == TRUE){
				$query = $this->get_info($id);
				
				$data = array(
					'active' => ABS($query[0]->active - 1) ,
				);
				$this->db->where('id', $id);
				$this->db->update('subscriber', $data);
			}
		}
		
		function delete($id)
		{
			if($this->session->userdata('admin_logged_in') == TRUE){
				$this->db->where('id', $id); 
				return $this->db->delete('subscriber');
			}
		}
		
		function get_info($id)
		{
			$this->db->where('id', $id);
			$this->db->from('subscriber');
			$query = $this->db->get();
			return $query->result();
		}
		
		function get($email)
		{
			$query = $this->db->get_where('subscriber', array('email' => trim($email)));
			return $query->row_array();
		}
		
		function confirm($sec_code)
		{
			if($sec_code != null) {
				$data = array(
					'active' => 1 ,
				);
				$this->db->where('MD5(id)', $sec_code);
				$this->db->update('subscriber', $data);
				return $this->db->affected_rows();
			}else{
				return 0;
			}
		}
		
		function un_subscribe($sec_code)
		{
			$this->db->where('MD5(id)', $sec_code);
			return $this->db->delete('subscriber');
		}
	}


/* End of file technology_model.php */
/* Location: ./application/models/admin/technology_model.php */